﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace devtm.Configuration.Validators
{

    /// <summary>
    /// 
    /// </summary>
    [DebuggerNonUserCodeAttribute()]
    public class ConnectionStringNameValidator : ConfigurationValidatorBase
    {
        public override bool CanValidate(Type type)
        {
            return (type == typeof(string));
        }

        /// <summary>
        /// Methode validate the value is valid.
        /// </summary>
        /// <param name="value"></param>
        public override void Validate(object value)
        {

            if (String.IsNullOrEmpty((string)value))
                return;

            foreach (ConnectionStringSettings item in System.Configuration.ConfigurationManager.ConnectionStrings)
                if (item.Name == value.ToString())
                    return;

            throw new ConfigurationErrorsException("invalid connection string name");
           
        }
    }


}
